﻿using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;

namespace ZYing.QPanel.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class QPanelWindows : HandyControl.Controls.Window
    {
        private readonly Quartz.IScheduler _scheduler;
        public QPanelWindows(Quartz.IScheduler scheduler)
        {
            _scheduler = scheduler ?? throw new System.ArgumentNullException(nameof(scheduler));
            InitializeComponent();
            this.Loaded += QPanelWindows_Loaded;
        }

        private void QPanelWindows_Loaded(object sender, RoutedEventArgs e)
        {
            var title = Path.GetFileName(Assembly.GetEntryAssembly().Location);
            if (!string.IsNullOrWhiteSpace(title)) this.Title = title;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (_scheduler.IsShutdown || _scheduler.InStandbyMode)
            {
                return;
            }
            if (!Helpers.MessageHelper.Confirm("任务仍在运行中，确定退出吗？"))
            {
                e.Cancel = true;
                return;
            }
        }
    }
}
